package com.ds.infrastructure.hyperspace.console.dto.apirouter;

import com.ds.infrastructure.hyperspace.console.dto.configdata.EndpointsDTO;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: yaozhendong
 * @create: 2019-11-08 16:46
 **/
@Data
@NoArgsConstructor
public class ApiRouterTargetEndpointConfig implements Serializable {
    private String namespace;
    private List<ApiRouterTargetNodesDTO> nodes = new ArrayList<>();

    public static ApiRouterTargetEndpointConfig toApiRouter(EndpointsDTO dto) {
        ApiRouterTargetEndpointConfig apiRouterTargetEndpointConfig = new ApiRouterTargetEndpointConfig();
        apiRouterTargetEndpointConfig.setNamespace(dto.getNamespace());
        //
        List<ApiRouterTargetNodesDTO> apiRouterNodesDTOList = new ArrayList<>();
        dto.getNodes().forEach(item -> apiRouterNodesDTOList.add(ApiRouterTargetNodesDTO.toApiRouter(item)));
        apiRouterTargetEndpointConfig.setNodes(apiRouterNodesDTOList);
        //
        return apiRouterTargetEndpointConfig;
    }
}
